package com.twinkle.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.twinkle.dao.ParamTrainResultMapper;
import com.twinkle.model.ParamTrainResult;
import com.twinkle.service.ParamTrainResultService;
import com.twinkle.utils.ParamTranslate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.List;

/**
 * @title: ParamTrainResultServiceImpl
 * @description:
 * @author: Paul
 * @date: 2023/4/4 9:43
 */
@Service
public class ParamTrainResultServiceImpl implements ParamTrainResultService {

    @Autowired
    ParamTrainResultMapper paramTrainResultMapper;

    @Override
    public ParamTrainResult getParamTrainResultByModelId(String modelId) {
        ParamTrainResult paramTrainResult = paramTrainResultMapper.selectOne(new QueryWrapper<ParamTrainResult>().eq("model_id", modelId));
        //格式化param
        StringBuffer paramFormat = new StringBuffer();
        String param = paramTrainResult.getParam();
        JSONObject paramObject = JSONObject.parseObject(param);
        for (String key : paramObject.keySet()) {
            paramFormat.append(ParamTranslate.getParamName(key) + " : " + paramObject.getString(key) + "\r\n");
        }
        paramTrainResult.setParam(paramFormat.toString());

        //截取图片名称

        String predDisImage = paramTrainResult.getPredDisImage();
        if (StringUtils.isNotBlank(predDisImage)) {
            String[] splitPredDisImage = predDisImage.split("\\/");
            predDisImage=splitPredDisImage[splitPredDisImage.length-1];
            paramTrainResult.setPredDisImage(predDisImage);
        }
        return paramTrainResult;
    }

    @Override
    public ParamTrainResult getParamTrainResultById(String id) {
        return null;
    }

    @Override
    public String getAllParamTrainResultJson(int page, int count) {
        return null;
    }

    @Override
    public String paramTrainResultListForUserAdd() {
        return null;
    }

    @Override
    public String addParamTrainResult(ParamTrainResult paramTrainResult) throws ParseException {
        return null;
    }

    @Override
    public String modifyParamTrainResult(ParamTrainResult paramTrainResult) {
        return null;
    }

    @Override
    public String deleteParamTrainResult(String id) {
        return null;
    }

    @Override
    public List<ParamTrainResult> getAllParamTrainResult() {
        return null;
    }

    @Override
    public String getAllParamTrainResultJsonBySearch(int page, int count, String algoName, String appName) {
        return null;
    }
}
